package com.wangku.springmvc.service;

import com.wangku.springmvc.dao.DaoSupport;
import com.wangku.springmvc.entity.Page;
import com.wangku.springmvc.entity.PageData;
import com.wangku.springmvc.utils.DateUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("buyerUserService")
public class BuyerUserService {

	@Resource(name = "daoSupport")
	private DaoSupport dao;

	// ======================================================================================

	/*
	 * 通过id获取数据
	 */
	public PageData findById(PageData pd) throws Exception {
		return (PageData) dao.findForObject("BuyUserMapper.find", pd);
	}

	/**
	 *
	 * 修改微信小程序登录时间
	 */
	public PageData editByUserId(PageData pd) throws Exception {
		return (PageData) dao.findForObject("BuyUserMapper.editByUserId", pd);
	}

	/*
	 * 
	 * /* 列表
	 */
	@SuppressWarnings("unchecked")
	public List<PageData> searchlist(Page page) throws Exception {
		return (List<PageData>) dao.findForList("BuyUserMapper.find", page);
	}

	// 分页查询买家用户信息
	@SuppressWarnings("unchecked")
	public List<PageData> searchlistPage(Page page) throws Exception {
		return (List<PageData>) dao.findForList(
				"BuyUserMapper.searchlistPage", page);
	}

	/*
	 * 保存
	 */
	public void save(PageData pd) throws Exception {
		pd.put("CreateTime", DateUtil.getTime());
		dao.save("BuyUserMapper.save", pd);
	}

	/*
	 * 修改
	 */
	public void edit(PageData pd) throws Exception {
		dao.update("BuyUserMapper.edit", pd);
	}

	/*
	 * 删除
	 */
	public void delete(PageData pd) throws Exception {
		dao.delete("BuyUserMapper.delete", pd);
	}

	@SuppressWarnings("unchecked")
	public List<PageData> findList(PageData pd) throws Exception {
		return (List<PageData>) dao.findForList("BuyUserMapper.findlist", pd);
	}

	// 分页查询买家用户信息
	@SuppressWarnings("unchecked")
	public List<PageData> findlistPage(Page page) throws Exception {
		return (List<PageData>) dao.findForList("BuyUserMapper.findlistPage", page);
	}
}
